package com.lastoffer2.adapter;

import java.util.List;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
import com.lastct.dao.Offer;
import com.lastoffer2.R;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class ImagePagerAdapter extends PagerAdapter {
		private LayoutInflater inflater;
		public  List<Offer> data;
		private Context context;


		public ImagePagerAdapter(List<Offer> data, Context context) {
			this.data = data;
			this.context = context;
			inflater = LayoutInflater.from(context);
		}

		@Override
		public void destroyItem(View container, int position, Object object) {
			((ViewPager) container).removeView((View) object);
		}

		@Override
		public void finishUpdate(View container) {
		}

		@Override
		public int getCount() {
			return data.size();
		}

		@Override
		public Object instantiateItem(View view, int position) {
			final View imageLayout =  inflater.inflate(
					R.layout.item_pager_image, null);
			final ImageView imageView = (ImageView) imageLayout
					.findViewById(R.id.image);
			
			UrlImageViewHelper.setUrlDrawable(imageView, data.get(position).getImage());
			

//
//						@Override
//						public void onLoadingComplete(Bitmap loadedImage) {
//							spinner.setVisibility(View.GONE);
//							Animation anim = AnimationUtils.loadAnimation(
//									MainActivity.this, R.anim.fade_in);
//							imageView.setAnimation(anim);
//							anim.start();
//						}
//
//						@Override
//						public void onLoadingCancelled() {
//							// Do nothing
//						}
//					});

			((ViewPager) view).addView(imageLayout, 0);
			return imageLayout;
		}

		@Override
		public boolean isViewFromObject(View view, Object object) {
			return view.equals(object);
		}

		@Override
		public void restoreState(Parcelable state, ClassLoader loader) {
		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View container) {
		}
	}